package com.xjd.transport.mock;

import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Date;

public class SocketClient2 {

	public static void main(String[] args) throws UnknownHostException, IOException {
		Client client = new Client();
		client.start();
		
		try {
			Thread.sleep(5000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		
		client.interrupt();
		System.out.println("interupt: " + System.currentTimeMillis());
		
		try {
			Thread.sleep(10000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println("main over: " + System.currentTimeMillis());
	}
	
	public static class Client extends Thread {
		public void run() {
			try {
				request();
			} catch (UnknownHostException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		
		public void request() throws UnknownHostException, IOException {
			Socket client = new Socket(InetAddress.getLocalHost(), 9090);
			
			OutputStream out = client.getOutputStream();
			
			for (int i=0; i<10; i++) {
				out.write(1);
			}
			
			System.out.println("write over: " + System.currentTimeMillis());
			
			try {
				Thread.sleep(10000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			System.out.println("Client over: " + System.currentTimeMillis());
		}
	}

}
